

    <div class="form">
      <form method="post">
        <noscript>
          <input type="text" name="title" value="{title}" /> <br />
          <input type="text" name="date" value="{date}" /> <br />
          <textarea name="text">{text}</textarea> <br />
          <textarea name="tags">{tags}</textarea> <br />
          <input type="submit" value="save" />
        </noscript>
        <script type="text/javascript">
          var id = '{id}';
          var ptag=new Array();
          document.write('<input type="text" name="title" value="{title}" /> <br />');
          document.write('<input type="text" name="date" value="{date}" /> <br />');
          document.write('<textarea name="text" id="text"></textarea> <br />');
          document.write('<input type="text" id="tags" value="" /> <br />');
          document.write('<input type="hidden" id="tags_hid" name="tags" value="{tags}" />');
          document.write('<div id="tags_text"></div><br />');
          document.write('<input type="submit" value="save post" />');
          var tag=new Array();

          $(document).ready(function(){
              $.ajax({
                  url: '/tags/?ajax=1',
                  dataType: "xml", 
                  success: function(xml){
                      $(xml).find("tag").each( function(){
                          tag[tag.length] = $(this).text();
                      });
                      $("#tags").autocomplete(tag);
                  }
              });
              $.ajax({
                  url: '/post/'+id+'/?ajax=1',
                  dataType: "xml", 
                  success: function(xml){
                      $(xml).find("text").each( function(){
                          $("textarea#text").val($(this).text());
                      });
                  }
              });
          
          }); 


          add_tag = function(t, id){
              if ( typeof(id)=='undefined') {
            	  ptag[ptag.length] = t;
            	  id = ptag.length;
              }
        	  document.getElementById('tags_hid').value = ptag.join(', ');
              $("#tags_text").append('<span id="'+id+'">'+t+'</span> ');
              $("#tags_text #"+id).bind("click", function(){del_tag(id);});
          } 

          del_tag = function(t) {
              ptag.splice(t,1);
              $("#tags_text").html('');
              document.getElementById('tags_hid').value='';
              for ( i=0; i<ptag.length ; i++ ) {
                  add_tag(ptag[i],i);
              }
          }
          
          ptag = document.getElementById('tags_hid').value.split(', ');
          for ( i=0; i<ptag.length ; i++ ) {
              add_tag(ptag[i],i);
          }
          
          document.getElementById("tags").onkeyup = function(){
        	  t = $("#tags").attr("value");
        	  if ( t[t.length-1]==',' ){
            	  add_tag(t.substr(0,t.length-1));
            	  $("#tags").attr({value:''});
        	  }
          }

        </script>
      </form>
    </div>
    